import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.filechooser.FileSystemView;


public class Main {

	static List<String> letters;
	
	public static void main(String[] args) {
		letters = new ArrayList<String>();
		scan();
		USBCheckTask scan = new USBCheckTask();
		Timer scanTimer = new Timer();
		scanTimer.schedule(scan, 6000, 6000);
	}

	private static void scan() {
		File[] roots = File.listRoots();
		for(int i=0;i<roots.length;i++) {
		    System.out.println("Root["+i+"]:" + roots[i] + " name: " + FileSystemView.getFileSystemView().getSystemDisplayName(roots[i]));
		    letters.add(FileSystemView.getFileSystemView().getSystemDisplayName(roots[i]));
		}
	}

	static class USBCheckTask extends TimerTask {
		@Override
		public void run() {
			int countLetters = File.listRoots().length;
			if (countLetters != letters.size()) {
				System.out.println("needs rescannig");
				scan();
			}
		}
	}
}
